<?php
/*
 * Created on Nov 26, 2008
 *
 */

class NetflixQueueItem {
	public $id;
	public $queue;
	public $netflixTitle;
	public $queuePosition;
	


	/**
	 *
	 *
	 * @param Netflix $netflix The $netflix session object
	 * @param SimpleXML $xml SimpleXML in the Netflix REST format for a queue item  
	 */


	function __construct($netflixQueue, $queuePosition, $netflixTitle) {
		$this->queue = $netflixQueue;

		$this->netflixTitle = $netflixTitle;
		
		$this->queuePosition = $queuePosition;	
		
		$this->saveToDb($this->queue->id);
	}


	function saveToDb($queueId){
		//Check if the title is already saved
		$insertQuery = "INSERT INTO queue_item (`queue_id`, `title_id`, `queue_position`)
						VALUES ('{$this->queue->id}', '{$this->netflixTitle->id}', '{$this->queuePosition}')";
		
		mysql_query($insertQuery) or die ("Query failed $insertQuery with error ".mysql_error());
	}
	

	function getNetflixTitle(){
		return $this->netflixTitle;
	}
	
	function toString(){
		return $this->queuePosition . ' - ' . $this->netflixTitle->toString();
	}
}


?>